package com.zhu.nio.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by ehsy_it on 2016/4/12.
 */
public class FileChannelPosition {

    public static void main(String[] args) throws IOException {
        RandomAccessFile aFile = new RandomAccessFile("D:/data/gather-write-data.txt", "rw");
        FileChannel channel = aFile.getChannel();

        channel.position(channel.size() + 20);

        ByteBuffer buf = ByteBuffer.allocate(20);
        buf.put("nihaiahaahaj".getBytes());
        buf.flip();

        channel.write(buf);

        aFile.close();
    }
}
